#include <iostream>
#include <boost/typeof/typeof.hpp>
#include <boost/signals2.hpp>
#include <boost/bind.hpp>

using namespace std;
using namespace boost;
using namespace boost::signals2;

int func(int value)
{
    return value * 2;
}

struct foo 
{
    int _v;

    int calc(int value, int fix)
    {
        return value * fix + _v; 
    }
};

template <typename T>
class calc
{
public:
    calc(T a): _a(a) {}
    T operator() (T value) 
    {
        return value * _a;
    }
private:
    T _a;
};

struct Add {
    typedef int result_type;
    int operator() (int a, int b) {
        return a+b; 
    }
};

template <typename T>
class combiner
{
public:
    typedef int result_type;

    template<typename InputIterator>
    result_type operator() (InputIterator begin, InputIterator end) const
    {
        if (begin == end)  {
            return result_type(); 
        }

        result_type sum = 0;
        for (InputIterator pos = begin; pos != end; ++pos) {
            sum += *pos;
        }
        return sum;
    }
};

int main()
{
    cout << "hello" << endl;

    signal<int(int), combiner<int> > sig1;
    sig1.connect(func);

    foo f;
    f._v = 3;
    sig1.connect(bind(&foo::calc, f, _1, 2)); 
    sig1.connect(calc<int>(3));

    BOOST_AUTO(ret, sig1(5));
    cout << "result sum: " << ret << endl;

    cout << bind(Add(), _1, _2) (3, 8) << endl;
}

